//
//  LeftSortsViewController.m
//  味·道
//
//  Created by lanou3g on 15/6/30.
//  Copyright (c) 2015年 WMR. All rights reserved.
//

#import "LeftSortsViewController.h"
#import "LeftTableViewCell.h"
#import "ClassNameModel.h"
#import "AppDelegate.h"
@interface LeftSortsViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain)UIImageView *backGroundImageView;//背景图片
@property (nonatomic,retain)NSMutableArray *dataSourceArray;//存储图片信息，以及标题数据源

@end

@implementation LeftSortsViewController
- (void)dealloc
{
    self.tableView = nil;
    self.backGroundImageView = nil;
    self.dataSourceArray = nil;
    self.rightVC = nil;
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataSourceArray = [NSMutableArray array];
    // Do any additional setup after loading the view.
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds];
    imageview.image = [UIImage imageNamed:@"leftbackimage"];
    self.backGroundImageView = imageview;
    [imageview release];
    
    UITableView *tableview = [[UITableView alloc] init];
    tableview.frame = self.view.bounds;
    tableview.rowHeight = 60;
    tableview.dataSource = self;
    tableview.delegate  = self;
    tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [tableview registerClass:[LeftTableViewCell class] forCellReuseIdentifier:@"left"];
    self.tableView = tableview;
    [tableview release];
    [self.view addSubview:self.backGroundImageView];
    [self.view addSubview:self.tableView];
}
//当View将要显示时创建控件
-(void)viewWillAppear:(BOOL)animated{
    
    
    ///初始化数据源数组,给数组赋值
    NSArray *array = @[@[@"热门菜谱",@"MenuListViewController",@"1.png"],@[@"三餐摇一摇",@"ThreeMealsViewController",@"2.png"],@[@"精彩专题",@"SpecialSubjectViewController",@"3.png"],@[@"定时提醒",@"TimeDreminderViewController",@"4.png"],@[@"养生之道",@"RegimenViewController",@"5.png"],@[@"视频私房菜",@"VideosViewController",@"6.png"],@[@"更多",@"MoreViewController",@"7.png"]];
    for (NSArray *modelArray in array) {
        ClassNameModel *model = [[ClassNameModel alloc] init];
        model.disName = modelArray[0];
        model.className = modelArray[1];
        model.imageName = modelArray[2];
        [self.dataSourceArray addObject:model];
        [model release];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSourceArray.count;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"left" forIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.backgroundColor = [UIColor clearColor];
    ClassNameModel *model = self.dataSourceArray[indexPath.row];
//    cell.picIV.image = [UIImage imageNamed:model.imageName];
    cell.titleLabel.text = model.disName;
    cell.titleLabel.textColor = [UIColor whiteColor];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [tempAppDelegate.LeftSlideVC closeLeftView];
    ClassNameModel *model = self.dataSourceArray[indexPath.row];
    [self.rightVC addViewWith:model];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 180;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 180)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
